package com.galina.notebook.persistence;


import java.io.Serializable;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyJoinColumn;
import javax.persistence.OneToMany;

import com.galina.notebook.persistence.enums.NoteType;

@Entity
public class Note implements Serializable  {

	private static final long serialVersionUID = -1918332637289230627L;
	
	private int id;
	private String content;
	private String label;
	private NoteType noteType;
	private Account account;
	private Map<Comment,Account> comments = new HashMap<Comment,Account>();
	
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}

	public NoteType getNoteType() {
		return noteType;
	}
	public void setNoteType(NoteType noteType) {
		this.noteType = noteType;
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@ManyToOne(cascade=CascadeType.ALL)

	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
	
	@OneToMany(cascade=CascadeType.ALL)
	@MapKeyJoinColumn(name="COMMENT_ID")
	@JoinTable(name="NOTE_COMMENTS_ACCOUNT", 
			joinColumns=@JoinColumn(name="NOTE_ID"),
			inverseJoinColumns=@JoinColumn(name="ACCOUNT_ID"))
	public Map<Comment,Account> getComments() {
		return comments;
	}
	public void setComments(Map<Comment,Account> comments) {
		this.comments = comments;
	}
	
	
}